var Wxparse = require('../../utils/wxParse/wxParse');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        show: false,
        shuxing: false,
        attribute: [], //属性框的数据
        brand: [],
        comment: [],
        info: [],
        gallery: [], //图片
        issue: [],
        productList: [],
        specificationList: [], //规格数据
        guige: [],
        yanse: [],
        id: '',
        gg: '',
    },
    formatPrice(price) {
        return price.toFixed(2); // 保留小数点后两位
    },
    shoppingcart() {
        const {
            id
        } = this.data;
        if (!id) return;
        wx.request({
            url: `http://admin.bsmall.byesame.com/wx/goods/detail?id=${id}`,
            data: {

            },
            method: "GET",
            success: (res) => {
                const info = res.data.data.info;
                info.retailPrice = this.formatPrice(info.retailPrice);
                info.counterPrice = this.formatPrice(info.counterPrice);
                console.log("商品", res);

                this.setData({
                    attribute: res.data.data.attribute,
                    brand: res.data.data.brand,
                    comment: res.data.data.comment.data,
                    info: res.data.data.info,
                    issue: res.data.data.issue,
                    productList: res.data.data.productList,
                    specificationList: res.data.data.specificationList,
                    gallery: res.data.data.info.gallery,
                    //   gg:res.data.data.specificationList[0].valueList[0].value,
                    //   guige:res.data.data.specificationList[0].valueList,
                    //   yanse:res.data.data.specificationList[1].valueList
                });
                console.log("attribute", this.data.attribute);
                if (res.data.data.info.detail != "") {
                    let that = this;
                    Wxparse.wxParse('goodsDetail', 'html', res.data.data.info.detail || "", that, 10)
                }
            }
        })
    },

    specification() {
        console.log(11111);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const dlitid = options.id;
        this.setData({
            id: dlitid
        });
        this.shoppingcart()
    },
    onClickButton() {
        this.setData({
            show: true
        });

    },
    onClose() {
        this.setData({
            show: false
        });
        this.setData({
            shuxing: false
        });
    },
    onClickIcon() {
        wx.switchTab({

            url: `/pages/shopping/shopping`,
        })
    },
    property() {
        this.setData({
            shuxing: true
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        this.shoppingcart()
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})